package Experiment3;

import java.util.ArrayList;
import java.util.List;

public class Student extends Person {
    private final List<Course> selectedCourses = new ArrayList<>();

    public Student(String studentId, String name, String gender) {
        super(studentId, name, gender);
    }

    public void selectCourse(Course course) {
        selectedCourses.add(course);
        System.out.println("学生 " + getName() + " 选择课程：" + course.getCourseName());
    }

    public void dropCourse(Course course) {
        if (selectedCourses.remove(course)) {
            System.out.println("学生 " + getName() + " 退选课程：" + course.getCourseName());
        } else {
            System.out.println("学生 " + getName() + " 未选该课程，无法退课！");
        }
    }

    public void printSchedule() {
        System.out.println("=== 学生 " + getName() + " 的课表 ===");
        System.out.println("课程编号\t课程名称\t上课地点\t上课时间\t授课教师");
        for (Course course : selectedCourses) {
            System.out.println(course.getCourseId() + "\t" + course.getCourseName() + "\t" +
                    course.getLocation() + "\t" + course.getTime() + "\t" +
                    getTeacherNameByCourse(course));
        }
        System.out.println("=========================");
    }

    private String getTeacherNameByCourse(Course course) {
        return "教师" + course.getTeacherId().substring(1);
    }

    public List<Course> getSelectedCourses() {
        return selectedCourses;
    }
}
